package com.example.collegevice.mapper;

import com.example.pojo.Student;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 操作admin相关数据接口
*/
@Mapper
public interface StudentMapper {
    @Insert("insert into student(username, password, name, role,  sex, code, college_id, score,avatar) " +
            "values(#{username}, #{password}, #{name},#{role},  #{sex}, #{code}, #{collegeId}, #{score},#{avatar})")
    void insert(Student student);

    @Select("select * from student where username = #{username}")
    Student selectByUsername(String username);

//    @Select("select student.*, college.name as collegeName from student left join college on student.college_id = college.id")
    @Select("select * from student")
    List<Student> selectAll();

//    @Select("select student.*, college.name as collegeName from student " +
//            "left join college on student.college_id = college.id " +
//            "where student.name like concat('%', #{name}, '%')")
    @Select("select * from student where name like concat('%', #{name}, '%')")
    List<Student> selectByName(String name);

    @Update("update student set username=#{username}, password=#{password}, role=#{role}, " +
            "avatar=#{avatar}, name=#{name}, sex=#{sex}, code=#{code}, college_id=#{collegeId}, score=#{score} " +
            "where id = #{id}")
    void updateById(Student student);

    @Delete("delete from student where id = #{id}")
    void deleteById(Integer id);

//    @Select("select student.*, college.name as collegeName from student " +
//            "left join college on student.college_id = college.id " +
//            "where student.id = #{id}")
    @Select("select * from student where id = #{id}")
    Student selectById(Integer id);

}